package com.github.thinwonton.showcase.springboot.springbatch.sample1;

import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.NonTransientResourceException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;

/**
 * 从数组中读取2个字符串
 *
 * @author hugo
 * @date 2018/12/6
 */
public class Reader implements ItemReader<String> {
    private String[] messages = {
            "Welcome to Spring Batch Example",
            "We use H2 Database for this example"};

    private int next;

    @Override
    public String read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
        if (next < messages.length) {
            System.out.println("Reader has data");
            return messages[next++];
        }
        System.out.println("Reader not any data");
        return null;
    }
}
